<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" v-has="'supply:add'" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('供应商')" v-has="'supply:exp'">导出</a-button>
      <a-upload name="file" v-has="'supply:imp'" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" v-has="'supply:delBatch'"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="supplyFullName" slot-scope="text, record">
          <a @click="handleDetail(record)"><j-ellipsis :value="text" :length="12"/></a>
        </template>
        <template slot="address" slot-scope="text, record">
          <j-ellipsis :value="text" :length="12"/>
        </template>
        <template slot="cateScope" slot-scope="text, record">
          <j-ellipsis :value="text" :length="12"/>
        </template>
        <template slot="remark" slot-scope="text, record">
          <j-ellipsis :value="text" :length="12"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
          <span v-has="'supply:edit'" >
            <a-divider type="vertical" />
            <a @click="handleEdit(record)">编辑</a>
          </span>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item v-has="'supply:del'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <mdm-supply-modal ref="modalForm" @ok="modalFormOk"></mdm-supply-modal>
    <mdm-supply-modal-drawer ref="modalDetail" @ok="modalDetailOk"></mdm-supply-modal-drawer>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import MdmSupplyModal from './modules/MdmSupplyModal'
  import MdmSupplyModalDrawer from './modules/MdmSupplyModal.Style#Drawer'
  import Area from '@/components/_util/Area'

  export default {
    name: 'MdmSupplyList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      MdmSupplyModal,
      MdmSupplyModalDrawer
    },
    data () {
      return {
        description: '供应商管理页面',
        // 表头
        columns: [
          {
            title:'供应商名称',
            align:"center",
            dataIndex: 'supplyFullName',
            width: 200,
            scopedSlots: { customRender: 'supplyFullName' }
          },
          {
            title:'省市区',
            align:"center",
            dataIndex: 'administrativeArea',
            scopedSlots: {customRender: 'pcaSlot'},
            width: 200
          },
          {
            title:'详细地址',
            align:"center",
            dataIndex: 'address',
            width: 240,
            scopedSlots: { customRender: 'address' }
          },
          {
            title:'成立时间',
            align:"center",
            dataIndex: 'setTime',
            width: 100,
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'注册资金',
            align:"center",
            dataIndex: 'registCapital',
            width: 100
          },
          {
            title:'网址',
            align:"center",
            dataIndex: 'webSite',
            width: 140
          },
          {
            title:'供应商类型',
            align:"center",
            width: 100,
            dataIndex: 'supplyType_dictText'
          },
          {
            title:'经营范围',
            align:"center",
            dataIndex: 'cateScope',
            width: 140,
            scopedSlots: { customRender: 'cateScope' }
          },
          {
            title:'行业',
            align:"center",
            width: 100,
            dataIndex: 'cateTypeCode_dictText'
          },
          {
            title:'企业性质',
            align:"center",
            width: 100,
            dataIndex: 'entTypeCode_dictText'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            width: 200,
            scopedSlots: { customRender: 'remark' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/mdm/supply/list",
          delete: "/mdm/supply/delete",
          deleteBatch: "/mdm/supply/deleteBatch",
          exportXlsUrl: "/mdm/supply/exportXls",
          importExcelUrl: "mdm/supply/importExcel",

        },
        dictOptions:{},
        pcaData:'',
        superFieldList:[],
      }
    },
    created() {
      this.pcaData = new Area()
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      getPcaText(code){
        return this.pcaData.getText(code);
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'supplyNo',text:'供应商编码',dictCode:''})
        fieldList.push({type:'string',value:'supplyFullName',text:'供应商名称',dictCode:''})
        fieldList.push({type:'string',value:'supplyShortName',text:'供应商简称',dictCode:''})
        fieldList.push({type:'string',value:'address',text:'详细地址',dictCode:''})
        fieldList.push({type:'date',value:'setTime',text:'成立时间'})
        fieldList.push({type:'BigDecimal',value:'registCapital',text:'注册资金',dictCode:''})
        fieldList.push({type:'string',value:'webSite',text:'网址',dictCode:''})
        fieldList.push({type:'string',value:'supplyType',text:'供应商类型',dictCode:'mdm_supply_type'})
        fieldList.push({type:'string',value:'cateScope',text:'经营范围',dictCode:''})
        fieldList.push({type:'string',value:'cateTypeCode',text:'行业',dictCode:'crm_cust_cate'})
        fieldList.push({type:'string',value:'entTypeCode',text:'企业性质',dictCode:'crm_ent_type'})
        fieldList.push({type:'string',value:'invBankNo',text:'银行账号',dictCode:''})
        fieldList.push({type:'string',value:'invBankName',text:'开户银行',dictCode:''})
        fieldList.push({type:'string',value:'invTaxNo',text:'纳税人识别号',dictCode:''})
        fieldList.push({type:'string',value:'invAddr',text:'地址',dictCode:''})
        fieldList.push({type:'string',value:'invTel',text:'电话',dictCode:''})
        fieldList.push({type:'pca',value:'administrativeArea',text:'省市区'})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      },
      handleDetail(record){
        this.$refs.modalDetail.edit(record);
        this.$refs.modalDetail.title="详情";
        this.$refs.modalDetail.disableSubmit = true;
      },
      modalDetailOk() {
        this.loadData();
        this.onClearSelected()
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>